package com.cmwa.solution.sys.msg.service.impl;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cmwa.solution.base.dao.BaseDao;
import com.cmwa.solution.base.service.impl.BaseServiceImpl;
import com.cmwa.solution.sys.msg.dao.IMsgEmpConfDao;
import com.cmwa.solution.sys.msg.service.IMsgEmpConfService;
import com.cmwa.solution.sys.msg.vo.MsgEmpConfVo;

@Service
@SuppressWarnings({"rawtypes"})
public class MsgEmpConfServiceImpl extends BaseServiceImpl<MsgEmpConfVo> implements IMsgEmpConfService{
	@Resource
	private IMsgEmpConfDao msgEmpConfDao;
	
	@Override
	public BaseDao<MsgEmpConfVo> getDao() {
		return msgEmpConfDao;
	}
	
	@Override
	public int insertConfEmpR(MsgEmpConfVo msgEmpConfVoR) {
		return msgEmpConfDao.insertConfEmpR(msgEmpConfVoR);
	}

	@Override
	public int insertConfEmpC(MsgEmpConfVo msgEmpConfVoC) {
		return msgEmpConfDao.insertConfEmpC(msgEmpConfVoC);
	}

	@Override
	public boolean deleteMsgEmpConfR(String msgconfid) {
		int pd=msgEmpConfDao.deleteMsgEmpConfR(msgconfid);
		if(pd>0){
			return true;
		}else{
			return false;
		}
	}
	
	@Override
	public boolean deleteMsgEmpConfC(String msgconfid) {
		int pd=msgEmpConfDao.deleteMsgEmpConfC(msgconfid);
		if(pd>0){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public MsgEmpConfVo getMsgEmpConfR(String msgconfid) {
		return msgEmpConfDao.getMsgEmpConfR(msgconfid);
	}
	
	@Override
	public MsgEmpConfVo getMsgEmpConfC(String msgconfid) {
		return msgEmpConfDao.getMsgEmpConfC(msgconfid);
	}

	@Override
	public Map<String, String> getMsgEmpConfNameIdByIds(String[] ids) {
		Map<String, String> rst = new HashMap<String, String>();
		String empNames = "";
		String empIds = "";
		if(ids != null && ids.length != 0) {
			List<Map> tmp = msgEmpConfDao.getMsgEmpConfNameIdByIds(ids);
			for (Map m : tmp) {
				empNames += m.get("EMNAME") + ",";
				empIds += m.get("EMPID") + ",";
			}
			if (empNames.length() > 0) {
				empNames = empNames.substring(0, empNames.length() - 1);
				empIds = empIds.substring(0, empIds.length() - 1);
			}
		}
		rst.put("empNames", empNames);
		rst.put("empIds", empIds);
		return rst;
	}

	@Override
	public List<MsgEmpConfVo> queryAllConfEmp() {
		return msgEmpConfDao.queryAllConfEmp();
	}

	@Override
	public List<MsgEmpConfVo> queryConfEmpByConfId(String confid) {
		return msgEmpConfDao.queryConfEmpByConfId(confid);
	}
	/**
	 * @author ex-lix
	 * @since  2016-04-20
	 */
	@Override
	public String[] findEmpNameByEmpIds(String empids){
		String[] nameid=new String[2];
		nameid[0]="";
		nameid[1]="";
		if(empids==null || "".equalsIgnoreCase(empids.trim())){
			return nameid;
		}
		String[] z=empids.split(",");
		Arrays.sort(z);
		String empids_query="";
		String empids_save="";
		for(String s : z){
			empids_query+=s+",";
			empids_save+=s+",";
		}
		if(empids_query.length()>0){
			empids_query=empids_query.substring(0, empids_query.length()-1);
		}
		if(empids_save.length()>0){
			empids_save=empids_save.substring(0, empids_save.length()-1);
		}
		String empname=msgEmpConfDao.findEmpNameByEmpIds(empids_query);
		nameid[0]=empname;
		nameid[1]=empids_save;
		return nameid;
	}
	
	
}
